package cn.stylefeng.guns.sys.modular.dataQualityCheckDetail.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.dataQualityCheckDetail.entity.QualityCheckDetail;
import cn.stylefeng.guns.sys.modular.dataQualityCheckDetail.mapper.QualityCheckDetailMapper;
import cn.stylefeng.guns.sys.modular.dataQualityCheckDetail.model.params.QualityCheckDetailParam;
import cn.stylefeng.guns.sys.modular.dataQualityCheckDetail.model.result.QualityCheckDetailResult;
import cn.stylefeng.guns.sys.modular.dataQualityCheckDetail.service.QualityCheckDetailService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 数据质量检查详情表 服务实现类
 * </p>
 *
 * @author author
 * @since 2020-11-20
 */
@Service
public class QualityCheckDetailServiceImpl extends ServiceImpl<QualityCheckDetailMapper, QualityCheckDetail> implements QualityCheckDetailService {

    @Override
    public void add(QualityCheckDetailParam param) {
        QualityCheckDetail entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(QualityCheckDetailParam param) {
        this.removeById(getKey(param));
    }

    @Override
    public void update(QualityCheckDetailParam param) {
        QualityCheckDetail oldEntity = getOldEntity(param);
        QualityCheckDetail newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public QualityCheckDetailResult findBySpec(QualityCheckDetailParam param) {
        return null;
    }

    @Override
    public List<QualityCheckDetailResult> findListBySpec(QualityCheckDetailParam param) {
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(QualityCheckDetailParam param) {
        param.setIsDelete(1);
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(QualityCheckDetailParam param) {
        return param.getDataQualityCheckDetailId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private QualityCheckDetail getOldEntity(QualityCheckDetailParam param) {
        return this.getById(getKey(param));
    }

    private QualityCheckDetail getEntity(QualityCheckDetailParam param) {
        QualityCheckDetail entity = new QualityCheckDetail();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
